<?php 
include "includes/session.php";
include "includes/comunes.php";

$sql="select * from (select * from  boletoventa,personas,vehiculo where boletoCliente=personaId and boletoVehiculo=idAuto) as T1";
$where=" where boletoId=".$_GET['bol_id'];
//realizo la consulta paro obtener los totales
$result= cons_sql_up($sql.$where);
$reg=mysql_fetch_array($result);

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Sistema de Gestion de Vehiculos</title>

<link href="estilos.css" rel="stylesheet" type="text/css" />

<!--libreria jquery central-->
<script src="jquery-ui/js/jquery-1.9.1.js"></script>
<!--fin libreria central-->

<!--Librerias para el combo-->
<script language="JavaScript" type="text/javascript" src="combos/jquery.chainedSelects.js"></script>
<!--fin libreria-->

<!--librerias ui-->
<link href="jquery-ui/css/ui-lightness/jquery-ui-1.10.2.custom.css" rel="stylesheet"/>
<script src="jquery-ui/js/jquery-ui-1.10.2.custom.js"></script>
<!--fin libreria-->
<!--estilo para el scroll-->
<style>
  .ui-autocomplete {
    max-height: 300px;
    overflow-y: auto;
    /* prevent horizontal scrollbar */
    overflow-x: hidden;
  }
  /* IE 6 doesn't support max-height
   * we use height instead, but this forces the menu to always be this tall
   */
  * html .ui-autocomplete {
    height: 300px;
  }
  </style>
<!--
  fin estilo scroll-->
<style type="text/css">
 
#tabla{	width: 100%; }
.fila-base{ display: none; } /* fila base oculta */
.eliminar{ cursor: pointer; color: #000; }
#tablagastos{	width: 100%; }
.fila-base-gastos{ display: none; } /* fila base oculta */
.eliminargasto{ cursor: pointer; color: #000; }
 
</style>



<script language="JavaScript" type="text/javascript">
$(function()
{




$("#enviar").submit(function () {

     var precioTotal= 2345
                  if (confirm('Esta seguro que confirma los datos cargados?')){ 
					   return true;
					}else
					   return false;
});

$( "#clidni" ).autocomplete({
			source: "autoPersona.php"
		});
        

$("#imgbus").click(function(evento){
      evento.preventDefault();
      $("#comprador").load("datosCliente.php", {dni: $("#clidni").val()});
   });
   
   
 $("#vehiculo").change(function(evento){
      evento.preventDefault();
      $("#precioVenta").load("precioVenta.php", {veh: $("#vehiculo").val()});
   });  
   
   
			 
   
   
 $("#contipo").change(function(evento){
      evento.preventDefault();
      $("#formaPago").load("formaPago.php", {tipo: $("#contipo").val()});
	   
   });  
 

     $('#clipro').chainSelect('#cliloc','comboprolocalidad.php',
	{
		before:function (target) //before request hide the target combobox and display the loading message
		{
			$("#loading").css("display","block");
			$(target).css("display","none");
		},
		after:function (target) //after request show the target combobox and hide the loading message
		{
			$("#loading").css("display","none");
			$(target).css("display","inline");
		}
	});

	
		
             
             
        
			 
			 
	$("#agregar").on('click', function(){
	$("#tabla tbody tr:eq(0)").clone().removeClass('fila-base').appendTo("#tabla tbody");
	});
 
	// Evento que selecciona la fila y la elimina 
	$(document).on("click",".eliminar",function(){
		var parent = $(this).parents().get(0);
		$(parent).remove();
	});
			 
			 
	$("#agregargasto").on('click', function(){
		$("#tablagastos tbody tr:eq(0)").clone().removeClass('fila-base-gastos').appendTo("#tablagastos tbody");
	});
 
	// Evento que selecciona la fila y la elimina 
	$(document).on("click",".eliminargasto",function(){
		var parent = $(this).parents().get(0);
		$(parent).remove();
	});
	
	
	
	//calculo el total
			 $(document).on("change","#montopago",function(){
                        importe_total = $("#precio").val ;
						$("#montogasto").each(
							function(index, value) {
								importe_total = importe_total + eval($(this).val());
								}
						);
						$("#total").val(importe_total);
             });
             
	

});
</script>
<link href="SpryAssets/SpryMenuBarHorizontal.css" rel="stylesheet" type="text/css" />
<script src="SpryAssets/SpryMenuBar.js" type="text/javascript"></script>
</head>

<body>

<div class="container">
<?php include "includes/head.php"?>
   <div class="content">
       <div class="tituloprincipal">
          <?php include 'includes/submenu.php';?>  
           <img src="jquery-ui/css/ui-flexigrid/images/magnifier.png" width="25" height="25" border="0"/> Visualizar Venta Nro <?php echo $_GET['bol_id']?></div>
       <form id="enviar"  method="POST" action="grabarBoletoVenta.php">
       <div class="contenedorpedido">
		  
	   
       
       
           <div id="comprador">
           <fieldset>
              <legend><b>Datos del Comprador</b></legend> 
                <table  width="100%">
                 <tr>
                      <td class="textotablamenuform">Tipo</td>
                      <td class="textotablamenuform">
					   <input type="hidden" class="campo_form"  id="id" value="<?php echo $_GET['per_id']?>" name="id" >
                          <select name="ventipo" id="ventipo" class="campo_form" required disabled>
						  <?php if ($reg['personaTipo']==1){
						         $sel1="selected";
								 $sel2="";}
								 else{
								 $sel2="selected";
								 $sel1="";}?>
								 
                              <option value='1' <?php echo $sel1?>>Persona Fisica</option>
                              <option value='2' <?php echo $sel2?>>Persona Juridica</option>
                         </select>
                      </td>
                      <td class="textotablamenuform">Dni/Cuit</td>
                      <td class="textotablamenuform">
                           <input type="number" class="campo_form" autocomplete="on" disabled placeholder="Ej. 28992993" id="vendni" name="vendni" value="<?php echo $reg['personaDniCuit']?>" required style="width:80%;">
                           <!--<img src="img/actualizar.jpg" width="20" id="imgbus" style="margin-top:15px;"/> -->
                      </td>
                      
                 </tr>
                   <tr>
                      <td class="textotablamenuform">Nombre y Apellido</td>
                      <td class="textotablamenuform" colspan="5">
                           <input type="text" class="campo_form" disabled  id="venape" name="venape" value="<?php echo $reg['personaNombre']?>" required>
                               
                      </td> 
                   </tr>
                   
                   <tr>
                      <td class="textotablamenuform">Telefono Fijo</td>
                      <td class="textotablamenuform">
                          <input type="number" class="campo_form" disabled placeholder="Ej. 03624 764244" value="<?php echo $reg['personaTelefonoFijo']?>" id="ventelf" name="ventelf">
                    
                      </td>
                      <td class="textotablamenuform">Telefono Celular</td>
                      <td class="textotablamenuform">
                          <input type="number" class="campo_form" disabled placeholder="Ej. 0362 154764244" id="ventelc" value="<?php echo $reg['personaTelefonoCelular']?>" name="ventelc">
                    
                      </td>
                      
                 </tr>
                   <tr>
                      
                      <td class="textotablamenuform">Direccion</td>
                      <td class="textotablamenuform" colspan="2">
                           <input type="text" class="campo_form"  disabled id="venape" value="<?php echo $reg['personaDireccion']?>" name="vendir" required>
                    
                      </td>
                       <td class="textotablamenuform">
                       


                     </td>
                       <td class="textotablamenuform" colspan="3">
                         


                     </td>
                 </tr>
				 <tr>
				 <td class="textotablamenuform">
				 Observacion
				 </td>
				 <td colspan="4">
				 <textarea name="venObse" cols="65" disabled class="campo_form"><?php echo $reg['personaObservaciones']?></textarea>
				 </td>
				 </tr>
                   
                   
                   
               </table>       
           </fieldset>  
           </div>
           
        <fieldset>
              <legend><b>Datos del Vehiculo</b></legend> 
	   <table  width="100%">
                 <tr>
                      <td class="textotablamenuform">Vehiculo</td>
                      <td class="textotablamenuform">
                          <input type="text" class="campo_form"  disabled id="venape" value="<?php echo obtener_desc_vehiculo_venta($reg['idAuto'])?>" name="vendir" required>
                      </td>
					  </table>
			</fieldset>	
       
           
           <div id="precioVenta">
		   <fieldset>
              <legend><b>Precio Venta</b></legend> 
               <table  width="100%">
                 <tr>
                      <td class="textotablamenuform"  width="10%">Precio de Venta</td>
                      <td class="textotablamenuform" colspan="2"  width="50%">
                          <input type="text" class="campo_form" value="$ <?php echo $reg['boletoMonto']?>" disabled id="precio" name="precio" required style="width:80%;">
               
                      </td>
                 </tr>
               </table>    
           </fieldset>
		   <fieldset>
              <legend><b>Forma de Pago</b></legend> 
              
           <table  style="text-align: center;border:1px solid #ccc" width="100%">
			<?php 
			 $sql="select * from formapago ";
			//armo el Where de la consutla
			$where=" where formaBoleto=".$_GET['bol_id'];
			$where.=" order by formaId "   ;
			 $result= cons_sql_up($sql.$where);
			 if(mysql_num_rows($result)>0):
			?>
			
			<tr>
			<th style="text-align: center;">Tipo</th>
			<th style="text-align: center;">Monto</th>
			<th style="text-align: center;" >Cheque</th>
			<th style="text-align: center;">Vto. Cheque</th>
			<th style="text-align: center;">Tasa</th>
			<th style="text-align: center;">Cuotas</th>
			</tr>
			
            
			 <?php while($reg1=mysql_fetch_array($result)):?>
			  <tr>
                    <td class="textotablamenuform" style="text-align: center;">
					<?php echo obtener_forma_pago($reg1['formaTipo'])?>
                   </td>
				   <td class="textotablamenuform" style="text-align: center;">
				   $ <?php   echo $reg1['formaMonto']?> 
				   </td>
				    <td class="textotablamenuform" style="text-align: center;">
				   <?php 
					if($reg1['formaTipo']==3)				   
					   echo $reg1['formaCheque'];
					   else
						echo "- -";
						?> 
				  
				   </td>
				   <td class="textotablamenuform" style="text-align: center;">
				    <?php   
					if($reg1['formaTipo']==3)
					echo format_fec($reg1['formaVtoCheque'],"/");
					else
					echo "- -"?> 
					</td>
					<td class="textotablamenuform" style="text-align: center;">
				    <?php   
					if($reg1['formaTipo']==2)
					echo $reg1['formaTasaMensual'];
					else
					echo "- -";
					?> 
					</td>
					<td class="textotablamenuform" style="text-align: center;">
				    <?php   
					if($reg1['formaTipo']==2)
					echo $reg1['formaCuotas'];
					else
					echo "- -";
					?> 
					</td>
					</tr>
		    <?php endwhile ?>	
			
                 
				 <?php else:?>
				 <tr>
				 <td class="textotablamenuform" colspan="4">
				 No existen registros asociados</td>
				 </tr>
				 <?php endif?>
                  
               </table>    
           </fieldset>
		    <fieldset>
              <legend><b>Propietario Anterior</b></legend> 
	   <table  width="100%">
				<?php 
				//busco los datos del dueño anterior
				$sql="select * from (select * from  boletocompra,personas where boletoVendedor=personaId) as T1 ";
				//armo el Where de la consutla
				$where=" where boletoVehiculo=".$reg['boletoVehiculo'];
				$resultAnt= cons_sql_up($sql.$where);
				$regAnt=mysql_fetch_array($resultAnt);
				?>
                 <tr>
                      <td class="textotablamenuform">Vendedor</td>
                      <td class="textotablamenuform">
                          <?php echo $regAnt['personaDniCuit']." ".$regAnt['personaNombre']?>
						  <a href="visualizarCliente.php?per_id=<?php echo $regAnt['personaId']?>"><img src="jquery-ui/css/ui-flexigrid/images/magnifier.png" width="25" height="25" border="0"/></a>
                 
                      </td>
					  </tr>
					
					 
					
					  
					  </table>
			</fieldset>	
		   
		   </div>
		      <fieldset>
              <legend><b>Observaciones</b></legend> 
	   <table  width="100%">
                 <tr>
                      <td class="textotablamenuform"></td>
                      <td class="textotablamenuform">
                          <textarea cols="95" rows="15" name="observacion" disabled id="observacion"><?php echo $reg['boletoObservacion']?></textarea>
                      </td>
					  </table>
			</fieldset>		
           
           <fieldset style="text-align: right;">  
            <table style="text-align: right;">
             <tr>
                    <td class="textotablamenuform" style="text-align: right;" colspan="5">
                         <input type="reset" name="reset" value="Limpiar"  class="boton_form"/>
                         <input name="submit" id="submit" type="submit" value="Grabar Boleto / Paso 2" class="boton_form"/>
                     </td>
                 </tr>
                   </table>       
           </fieldset>  
           
           
           
       </div>
   </form>
       <div class="clear"></div>
   <br>
   </div>
  <?php include "includes/pie.php"?>
  
</div>
</body>
</html>
